(* exercice 2 *) pair([X|L],(X,Y)):-member(Y,L). pair([_|L],(X,Y)):- pair(L,(X,Y)). all_arcs(L,P):-bagof(X,pair(L,X),P). subsets([],[]). subsets([X|L],[X|T]):-subsets(L,T). subsets([_|L],T):-subsets(L,T). all_graphs(S,GG):-all_arcs(S,P), bagof(G,subsets(P,G),GG). mem(Z, [(X,Y)|G]) :- (Z==X,!);(Z==Y,!);mem(Z,G). degre(G,Y,N):- mem(Y,G) -> deg(G,Y,N); fail. deg([],_,0). deg([(Y,Z)|G],X,N):-((X==Y,!);(X==Z,!)),deg(G,X,R), N is R+1. deg([(Y,Z)|G],X,N):-X\==Y,X\==Z, deg(G,X,N). vertex_list([],[]).vertex_list([(X,Y)|G],[X,Y|L]):-vertex_list(G,L), not(member(X,L)), not(member(Y,L)),!. vertex_list([(X,Y)|G],[X|L]):-vertex_list(G,L), not(member(X,L)), member(Y,L),!.vertex_list([(X,Y)|G],[Y|L]):-vertex_list(G,L), not(member(Y,L)), member(X,L),!.vertex_list([(_,_)|G],L):-vertex_list(G,L). eulerian(G):-vertex_list(G,L),ap(L,G). ap([],_). ap([X|L],G):-degre(G,X,N), N mod 2 =:= 0, ap(L,G). all_eulerians(L,E):-all_arcs(L,P), bagof(G, (subsets(P,G), eulerian(G)), E). (* exercice 3 *) move(X,Y):- (X>2, Y is X-3); (X>3, Y is X-4). gagne(X):-move(X,Y), not(gagne(Y)). gagne_bis(X):- (X mod 7)>2.